package com.wenwei.adapter;

import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wenwei.bean.ParkListBean;
import com.wenwei.parking.R;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/8/22.
 */
public class AdminAdapter extends RecyclerView.Adapter<AdminAdapter.MyViewHolder> {


    private CallBack mCallBack;
    public void setCallBack(CallBack callBack){
        this.mCallBack = callBack;
    }
    public interface CallBack{
        void onItemClick(int id);
    }

    private List<ParkListBean.DataBean> mList;
    public void setmList(List<ParkListBean.DataBean> list){
        this.mList = list;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_admin, null));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {

//        当前车位的状态，未使用：0，预约：1，使用中：2，故障：-1

        holder.itemAdminNum.setText(mList.get(position).getParkCarNum());
        holder.itemPositionTv.setText(""+mList.get(position).getId());
        if(mList.get(position).getState() == 0){
            holder.itemAdminStatus.setTextColor(Color.parseColor("#45bcc6"));
            holder.itemAdminStatus.setText("空闲>>");
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mCallBack.onItemClick(mList.get(position).getParkId());
                }
            });
        }else if (mList.get(position).getState() == 1){
            holder.itemAdminStatus.setTextColor(Color.parseColor("#F1982F"));
            holder.itemAdminStatus.setText("预约");
        }else if(mList.get(position).getState() == 2){
            holder.itemAdminStatus.setTextColor(Color.parseColor("#e31b1b"));
            holder.itemAdminStatus.setText("占用");
        }else if (mList.get(position).getState() == -1){
            holder.itemAdminStatus.setTextColor(Color.parseColor("#e31b1b"));
            holder.itemAdminStatus.setText("故障");
        }



    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.item_admin_num)
        TextView itemAdminNum;
        @Bind(R.id.item_admin_status)
        TextView itemAdminStatus;
        @Bind(R.id.position_tv)
        TextView itemPositionTv;
        public MyViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

}
